package com.xt.LibaryDeskManager.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.xt.LibaryDeskManager.dao.MessageMapper;
import com.xt.LibaryDeskManager.dto.MessageDto;
import com.xt.LibaryDeskManager.service.MessageService;
import com.xt.LibaryDeskManager.utils.StrUtils;
import com.xt.LibaryDeskManager.vo.MessageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author 童归权
 * @version 1.0 2021/2/8
 */
@Service
public class MessageServiceImpl implements MessageService {
    @Autowired
    private MessageMapper messageMapper;

    @Override
    public int getCount() throws Exception {
        return messageMapper.getCount();
    }

    @Override
    public Map getAllMessage(Integer page, Integer limit) throws Exception {
        Page page1= PageHelper.startPage(page,limit);
        List<MessageDto> list= messageMapper.getAllMessage();
        return StrUtils.creatMap(list,page1.getTotal());
    }

    @Override
    public int deleteMessage(int mid) throws Exception {
        return messageMapper.deleteMessage(mid);
    }

    @Override
    public int updateMessage(MessageVo messageVo) throws Exception {
        return messageMapper.updateMessage(messageVo);
    }

    @Override
    public int addMessage(MessageVo messageVo) throws Exception {
        return messageMapper.addMessage(messageVo);
    }
}
